$(function () {
    obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form: null,
        dom: {
            oldPwd: null,
            pwd: null,
            confirm: null,
            saveBtn: null
        },
        init: function () {
            this.form = $('#ff');

            this.dom.oldPwd  = $('#oldPwd');
            this.dom.pwd     = $('#pwd');
            this.dom.confirm = $('#confirmPwd');
            this.dom.saveBtn = $('#save');

            this.listener();
        },
        listener: function () {
            var $this = this;
            //保存修改
            $this.dom.saveBtn.click(function () {
                $this.funObj().saveChange();
            });
        },
        funObj: function () {
            var $this = this;
            return {
                saveChange: function () {
                    var oldPwd  = $this.dom.oldPwd.passwordbox('getValue');
                    var pwd     = $this.dom.pwd.passwordbox('getValue');
                    var confirm = $this.dom.confirm.passwordbox('getValue');
                    if(pwd==''||confirm==''||oldPwd==''){
                        window.top.sendErrorMsg('参数为空');
                        return false;
                    }
                    if(pwd != confirm){
                        window.top.sendErrorMsg('两次输入的密码不一致');
                        return false;
                    }
                    $.ajax({
                        url: baseUrl+'mobile/mine/saveChange',
                        dataType:'json',
                        type:'post',
                        data:{oldPwd:oldPwd,pwd:pwd,confirm:confirm},
                        complete:function (XMLHttpRequest) {
                            var result = XMLHttpRequest.responseJSON || XMLHttpRequest.responseText;
                            if(result.code === 200){
                                window.top.sendSuccessMsg(result.msg);
                            }else {
                                window.top.sendErrorMsg(result.error || result);
                            }
                        }
                    });

                }
            }
        }
    }
};